package com.yueya.business.knowledge.model;

import java.util.List;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;

@SuppressWarnings("serial")
public class Knowledge extends Model<Knowledge> {
	
	public static final Knowledge dao = new Knowledge();

	public Record findDetailById(String knowledgeId) {
		if(StrKit.isBlank(knowledgeId)) return null;
		String sql = "select k.*, kt.knowledge_text, kt.knowledge_html, d.dict_name as knowledge_type_name "
				+ " from jg_knowledge k "
				+ "left join jg_knowledge_text kt on kt.knowledge_id = k.knowledge_id "
				+ "left join t_dict d on d.dict_value = k.knowledge_type and d.category = 'knowledge_type' "
				+ "where k.knowledge_id = ? ";
		return Db.findFirst(sql, knowledgeId);
		
	}

	public Integer getOrdernum() {
		// TODO Auto-generated method stub
		String sql = "select max(order_num) order_num from jg_knowledge where del_flag = '0'";
		Knowledge knowledge = dao.findFirst(sql);
		if(null != knowledge && null != knowledge.get("order_num")) {
			return (Integer)knowledge.get("order_num")+1;
		}else {
			return 1;
		}
	}

	public List<Record> findAllKnowledgeType() {
		String sql = "select * from t_dict where category = 'knowledge_type' ";
		return Db.find(sql);
	}

}
